home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Language/OS - Multiplatform Resource Library
/
LANGUAGE OS.iso
/
oper_sys
/
oasis
/
oasis1-1.lha
/
oasis-1.1
/
bind.c
< prev
next >
Wrap
C/C++ Source or Header
|
1992-05-01
|
5KB
|
140 lines
/*==========================================================================*
Oasis Alpha Version 1.1 (C) Copyright 1992 Fah-Chun Cheong
Revised: 5/1/92 by: fcc@eecs.umich.edu and The University of Michigan
------------------------------------------------------------------------
Permission to use, copy, modify, distribute, sell and resell Oasis Alpha
software and its documentation for any purpose and without fee is hereby
granted, provided that the authorship be appropriately credited and
acknowledged, and that the above copyright notice appear in all copies
and both the copyright notice and this permission notice appear in
supporting documentation. The author makes no representations about the
suitability of this software for any purpose. It is provided "as is"
without express or implied warranty. Oasis Alpha is free, caveat emptor!
------------------------------------------------------------------------
To request Oasis Alpha source code: oasis-alpha-request@eecs.umich.edu
To enroll in the mailing list: oasis-alpha-request@eecs.umich.edu
To send bug reports: oasis-alpha-bugs@eecs.umich.edu
To discuss openly all matters Oasis: oasis-alpha@eecs.umich.edu
*==========================================================================*/
#include "gener.h"
#define SNO 10
static char *stab[SNO] = {
"$root",
"$handle",
"$listc",
"$listi",
"$listf",
"$listp",
"$arrayc",
"$arrayi",
"$arrayf",
"$arrayp"
};
int read_program(name, bufp)
char *name;
char **bufp;
{
char name_p[1024];
int fd;
int size;
sprintf(name_p, "%s.p", name);
if ((fd = open(name_p, 0)) < 0) {
perror("opening program file");
exit(-1);
}
size = lseek(fd, 0L, 2);
*bufp = (char *) malloc(size + 3);
lseek(fd, 0L, 0);
read(fd, *bufp + 1, size);
(*bufp)[0] = '\n';
(*bufp)[size + 1] = '\n';
(*bufp)[size + 2] = '\0';
close(fd);
fprintf(stderr, "\"%s\":\t%8d bytes read.\n", name_p, size);
return size + 3;
}
int write_package(name, bufv, argc)
char *name;
char **bufv;
int argc;
{
char name_t[1024];
int fd;
int size = 0;
int i;
sprintf(name_t, "%s.t", name);
if ((fd = creat(name_t, 0600)) < 0) {
perror("creating transcode package");
exit(-1);
}
for (i = 1; i < argc - 1; i++)
size += write(fd, bufv[i], strlen(bufv[i]));
close(fd);
fprintf(stderr, "\"%s\":\t%8d bytes written.\n", name_t, size);
return size;
}
void main(argc, argv)
int argc;
char *argv[];
{
char **tbufv = (char **) calloc(argc, sizeof(char **));
int i, j, k;
if (argc < 3) {
fprintf(stderr, "Usage: %s program [...] package\n", argv[0]);
exit(-1);
}
init_gen(SNO, stab);
for (i = 1; i < argc - 1; i++) {
char *pbuf;
int size = read_program(argv[i], &pbuf);
tbufv[i] = (char *) malloc(size * 16);
generate(pbuf, tbufv[i]);
free(pbuf);
}
for (i = 0; i < pno; i++)
for (k = ptab[i].isa; k != 0; k = ptab[k].isa)
for (j = ptab[k].mno; --j >= 0;)
if (ptab[i].mtab[j] == 0)
ptab[i].mtab[j] = ptab[k].mtab[j];
emit0 (".data");
emit0 (".align");
globl ("cno");
word (pno);
globl ("ctab");
for (i = 0; i < 10; i++) word(0);
for (; i < pno; i++) addrC(i);
globl ("dtab");
for (i = 0; i < 10; i++) word(0);
for (; i < pno; i++) addrM(i);
for (i = 10; i < pno; i++) {
labelM(i);
if (ptab[i].mno == -1)
err1("Undefined program `%s'.\n", ptab[i].name);
else if (ptab[i].mtab[0] == 0) word(0);
else addrL(ptab[i].mtab[0], 0);
for (j = 1; j < ptab[i].mno; j++) {
addrL(ptab[i].mtab[j], j);
if (ptab[i].mtab[j] == 0)
err2("Undefined method %s::%d.\n", ptab[i].name, j);
}
}
globl ("stab");
for (i = 0; i < pno; i++) addrS(i);
for (i = 0; i < pno; i++) {
labelS(i);
emit0L(".ascii", ptab[i].name);
}
emit0 (".align");
write_package(argv[argc - 1], tbufv, argc);
}